﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace MengCC.Core.Data
{
    public interface IBaseRepository<TEntity,TIdentityType> where TEntity:BaseEntity<TIdentityType>
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="TEntity"></param>
        /// <returns></returns>
        TEntity Add(TEntity TEntity);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="TEntity"></param>
        /// <param name="updateColumns">指定更新的列</param>
        /// <returns></returns>
        bool Update(TEntity TEntity, Expression<Func<TEntity, object>> updateColumns=null);
        /// <summary>
        /// 删除
        /// （使用泛型 IdentityType 避免装拆箱）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        bool Delete(TIdentityType id);
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TEntity Get(TIdentityType id);
        /// <summary>
        /// 返回符合条件的第一个对象
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="orderby"></param>
        /// <param name="orderByType">true asc ,false desc</param>
        /// <returns></returns>
        TEntity Get(Expression<Func<TEntity, bool>> expression = null, Expression<Func<TEntity, object>> orderby = null, bool orderByType=false);
        /// <summary>
        /// 获取所有
        /// </summary>
        /// <param name="expression">条件表达式</param>
        /// <param name="orderby">排序表达式</param>
        /// <param name="orderByType">true asc ,false desc</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetList(Expression<Func<TEntity, bool>> expression = null, Expression<Func<TEntity, object>> orderby = null, bool orderByType = false);

        /// <summary>
        /// 查询总数
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        int Count(Expression<Func<TEntity, bool>> expression = null);

        /// <summary>
        /// 分页获取
        /// </summary>
        /// <param name="pageIndex">起始页</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="columns">选择的列</param>
        /// <param name="where">条件表达式</param>
        /// <param name="orderby">排序表达式</param>
        /// <param name="orderByType">true asc ,false desc</param>
        /// <returns></returns>
        PaggingEntity<TEntity> GetPaggingList(int pageIndex, int pageSize = 10, Expression<Func<TEntity,object>> columns = null, Expression<Func<TEntity, bool>> where = null, Expression<Func<TEntity, object>> orderby = null, bool orderByType = false);

    }
}
